package com.liupaik.pennmarketplace;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MyItemsSelector extends ListActivity {
	
//	private MyItemsArrayAdapter m_adapter;

	
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.myitemsselect);
        
//      MyItemsSelectorRow sellrow = new MyItemsSelectorRow();
//		sellrow.setMainLabel("Review Your Listings");
//		sellrow.setDescription("See if anyone has replied to your sales listings!");
//		MyItemsSelectorRow buyrow = new MyItemsSelectorRow();
//		buyrow.setMainLabel("Potential Purchases");
//		buyrow.setDescription("Check if sellers have responded to your interest!");
		
//		ArrayList<MyItemsSelectorRow> arr = new ArrayList<MyItemsSelectorRow>();
//		arr.add(sellrow);
//		arr.add(buyrow);
		
        String[] listItems = {"Review Your Listings", "Potential Purchases"}; 
        
//		this.m_adapter = new MyItemsArrayAdapter(MyItemsSelector.this, R.layout.myitemsrow, arr);
//		setListAdapter(this.m_adapter);
        setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems));
        
        
        
        
    }
    
    
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    //super.onListItemClick(l, v, position, id);
    	if (position == 0){
    		Intent i = new Intent(MyItemsSelector.this, MyItems.class);
    		View view = MyItemsGroup.group.getLocalActivityManager()
        	.startActivity("ShowMyListings", i
        			.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
        			.getDecorView();
            MyItemsGroup.group.replaceView(view);
    	}
    	else if (position == 1){
    		Intent i = new Intent(MyItemsSelector.this, MyItems.class);
    		View view = MyItemsGroup.group.getLocalActivityManager()
        	.startActivity("ShowMyListings", i
        			.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
        			.getDecorView();
            MyItemsGroup.group.replaceView(view);
    	}
//    String selection = l.getItemAtPosition(position).toString();
//    Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
    }
    
//    
//    private class MyItemsArrayAdapter extends ArrayAdapter<MyItemsSelectorRow> {
//
//        private ArrayList<MyItemsSelectorRow> items;
//
//        public MyItemsArrayAdapter(Context context, int textViewResourceId, ArrayList<MyItemsSelectorRow> items) {
//                super(context, textViewResourceId, items);
//                this.items = items;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
////                View v = convertView;
////                if (v == null) {
////                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
////                    v = vi.inflate(R.layout.myitemsrow, null);
////                }
////                MyItemsSelectorRow o = items.get(position);
////                if (o != null) {
////                        TextView tt = (TextView) v.findViewById(R.id.toptext);
////                        TextView bt = (TextView) v.findViewById(R.id.bottomtext);
////                        if (tt != null) {
////                              tt.setText(o.getMainLabel());
////                        }
////                        if(bt != null){
////                              bt.setText(o.getDescription());
////                        }
////                }
////                return v;
//                
//                
//                
//                LayoutInflater vi = getLayoutInflater();
//                View v = vi.inflate(R.layout.myitemsrow, parent, false);
//
//                MyItemsSelectorRow o = this.items.get(position);
//                if (o != null) {
//                        TextView tt = (TextView) v.findViewById(R.id.toptext);
//                        TextView bt = (TextView) v.findViewById(R.id.bottomtext);
//                        tt.setText(o.getMainLabel());
//                        bt.setText(o.getDescription());
//                }
//                return v;
//        }
//    }

}
